#include "progresswidget.h"

#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>

ProgressWidget::ProgressWidget(int shell_size, int all_workers, QWidget *parent)
    : QWidget(parent)
    , m_books(new QProgressBar)
    , m_working(new QProgressBar)
    , m_waiting(new QProgressBar)
{
    m_books->setMaximum(shell_size);
    m_books->setMinimum(0);
    m_books->setValue(0);
    m_books->setTextVisible(true);

    m_working->setMaximum(all_workers);
    m_working->setMinimum(0);
    m_working->setValue(0);
    m_working->setTextVisible(true);

    m_waiting->setMaximum(all_workers);
    m_waiting->setMinimum(0);
    m_waiting->setValue(all_workers);
    m_waiting->setTextVisible(true);

    QVBoxLayout *main = new QVBoxLayout;
    QLabel *shell_label = new QLabel("Book shell:");
    QLabel *working_label = new QLabel("Working:");
    QLabel *waiting_label = new QLabel("Waiting:");

    QHBoxLayout *shell_layout = new QHBoxLayout;
    shell_layout->addWidget(shell_label);
    shell_layout->addWidget(m_books);

    QHBoxLayout *working_layout = new QHBoxLayout;
    working_layout->addWidget(working_label);
    working_layout->addWidget(m_working);

    QHBoxLayout *waiting_layout = new QHBoxLayout;
    waiting_layout->addWidget(waiting_label);
    waiting_layout->addWidget(m_waiting);

    main->addLayout(shell_layout);
    main->addLayout(working_layout);
    main->addLayout(waiting_layout);
    setLayout(main);
}

void ProgressWidget::new_book()
{
    m_books->setValue(m_books->value() + 1);
}

void ProgressWidget::new_waiting()
{
    m_waiting->setValue(m_waiting->value() + 1);
    m_working->setValue(m_working->value() - 1);
}

void ProgressWidget::new_working()
{
    m_working->setValue(m_working->value() + 1);
    m_waiting->setValue(m_waiting->value() - 1);
}
